• 2022-08-12
  • unique
  • kb
  • system
  • it

get FS magic number

Get the magic number for a filesystem, lsblk and df only show the name. This Program can be used to get the hex magic id of an FS.

on gitlab

package main

import (
	"fmt"
	sys "golang.org/x/sys/unix"
	"os"
)

// usage ./prog /mount/point
func main() {
	stat := sys.Statfs_t{}
	if len(os.Args) < 2 {
		fmt.Printf("not enough args\n")
		os.Exit(-1)
	}
	if sys.Statfs(os.Args[1], &stat) != nil {
		fmt.Printf("error\n")
		os.Exit(-1)
	}
	fmt.Printf("0x%08X\n", stat.Type)
}